<template>
	<el-dialog v-model="visible" title="手动同步" :close-on-click-modal="false" :width="1300" draggable>
		<p style="margin-bottom: 16px;">共搜索到 {{state.total}} 条有效数据</p>
		<el-table
			v-loading="state.dataListLoading"
			:data="state.dataList"
			border
			style="width: 100%"
			@selection-change="selectionChangeHandle"
			@sort-change="sortChangeHandle"
		>
			<el-table-column prop="stffNm" label="姓名" header-align="center" align="center"></el-table-column>
			<el-table-column prop="gdrNm" label="性别" header-align="center" width="90" align="center"></el-table-column>
			<el-table-column prop="stffCd" label="工号" header-align="center" width="90" align="center"></el-table-column>
			<el-table-column prop="idCrdNo" label="身份证号" header-align="center" width="180" align="center"></el-table-column>
			<el-table-column prop="slfTelNo" label="电话" header-align="center" align="center"></el-table-column>
			<el-table-column prop="stffCgyNm" label="职工类别" header-align="center" align="center"></el-table-column>
			<el-table-column prop="affltDptNm" label="所属科室" header-align="center" align="center"></el-table-column>
			<el-table-column prop="affltWrdNm" label="所属病区" header-align="center" align="center"></el-table-column>
			<el-table-column prop="crtTm" label="创建时间" header-align="center" align="center">
				<template #default="scope">
					{{ parseTime(scope.row.crtTm, '{y}-{m}-{d}') }}
				</template>
			</el-table-column>
			<el-table-column prop="updDt" label="更新时间" header-align="center" align="center">
				<template #default="scope">
					{{ parseTime(scope.row.updDt, '{y}-{m}-{d}') }}
				</template>
			</el-table-column>
			<el-table-column prop="type" label="变更原因" header-align="center" align="center"></el-table-column>
			<!-- <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
				<template #default="scope">
					<el-button v-auth="'sys:role:connect:update'" type="primary" link @click="del(scope.row)">删除</el-button>
				</template>
			</el-table-column> -->
		</el-table>
		<el-pagination
			:current-page="state.page"
			:page-sizes="state.pageSizes"
			:page-size="state.limit"
			:total="state.total"
			layout="sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>
		<template #footer>
			<div style="width: 100%; text-align: center;">
				<el-button @click="moveConfirm" :loading="btnLoading" :disabled="state.total == 0" type="primary">确认同步</el-button>
				<el-button @click="visible = false">取消</el-button>
			</div>
		</template>
	</el-dialog>
</template>

<script setup lang="ts" name="SysMenuIndex">
import { useCrud } from '@/hooks'
import { reactive, ref } from 'vue'
import { IHooksOptions } from '@/hooks/interface'
import { ElMessage, ElMessageBox } from 'element-plus/es'
import store from '@/store'
import { parseTime } from '@/utils/tool'
import { SynsUserInfo } from '@/api/sys/user'

const emit = defineEmits(['refreshDataList'])

const visible = ref(false)
const btnLoading = ref(false)

const init = () => {
	visible.value = true
	getDataList()
}

const moveConfirm = () => {
	btnLoading.value = true
	SynsUserInfo({}).then(res => {
		if (res.code == 0) {
			ElMessage.success({
				message: '手动同步成功！',
				duration: 1000,
			})
			visible.value = false
			emit('refreshDataList')
		} else {
			ElMessage.error({
				message: '手动同步失败,请重试！',
				duration: 1000,
			})
		}
		btnLoading.value = false
	}).catch(err => {
		btnLoading.value = false
	})
}

const state: IHooksOptions = reactive({
	dataListUrl: '/sys/user/sync-user-info-list',
	queryForm: {}
})

const { getDataList, sizeChangeHandle, selectionChangeHandle, sortChangeHandle, currentChangeHandle, deleteBatchHandle } = useCrud(state)
defineExpose({
	init
})
</script>

<style lang="scss" scoped>
.transfer :deep(.el-transfer-panel) {
	min-width: 290px;
}
::v-deep .el-transfer-panel__item.el-checkbox {
	margin-right: 0;
}
</style>
